//
//  MGRequestService+My.m
//  MortgageHelper
//
//  Created by zhangxiang on 16/11/18.
//  Copyright © 2016年 zhangxiang. All rights reserved.
//
#import "NSObject+MJKeyValue.h"
#import "MGRequestService+My.h"
#import "MGRequestService+Private.h"

@implementation MGRequestService (My)

//登录
+ (NSURLSessionDataTask *)requestloginWithuserName:(NSString *)userName AndPassword:(NSString *)password success:(void(^)(MGBaseRspModel *model))success
                                                  failure:(FailureResponseBlock)failure{
    
    NSString *api = @"/app/user/login";
    NSDictionary *parameters =[NSMutableDictionary dictionaryWithObjectsAndKeys:userName,@"userName",password,@"password", nil];
    
    NSURLSessionDataTask *task = [MGRequestService dataTaskWithMethodType:MGHTTPMethodTypePOST api:api parameters:parameters success:^(id responseObject) {
        MGBaseRspModel *model = [MGBaseRspModel MJmodelWithResponseObject:responseObject];
        if (success) {
            success(model);
        }
    } failure:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
    return task;

}

// 注册

+ (NSURLSessionDataTask *)requestRegisterWithuserName:(NSString *)userName AndPassword:(NSString *)password success:(void(^)(MGBaseRspModel *model))success
                                              failure:(FailureResponseBlock)failure{
    
    NSString *api = @"/app/user/register";
    NSDictionary *parameters =[NSMutableDictionary dictionaryWithObjectsAndKeys:userName,@"userName",password,@"password", nil];
    
    NSURLSessionDataTask *task = [MGRequestService dataTaskWithMethodType:MGHTTPMethodTypePOST api:api parameters:parameters success:^(id responseObject) {
        MGBaseRspModel *model = [MGBaseRspModel MJmodelWithResponseObject:responseObject];
        if (success) {
            success(model);
        }
    } failure:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
    return task;
    
}

// 修改密码

+ (NSURLSessionDataTask *)requestModifyThePasswordWitholdPassword:(NSString *)oldPassword AndnewPassword:(NSString *)newPassword success:(void(^)(MGBaseRspModel *model))success
                                                          failure:(FailureResponseBlock)failure{
    NSString *api = @"/app/user/updatePassword";
    NSDictionary *parameters =[NSMutableDictionary dictionaryWithObjectsAndKeys:oldPassword,@"oldPassword",newPassword,@"newPassword", nil];
    
    NSURLSessionDataTask *task = [MGRequestService dataTaskWithMethodType:MGHTTPMethodTypePOST api:api parameters:parameters success:^(id responseObject) {
        MGBaseRspModel *model = [MGBaseRspModel MJmodelWithResponseObject:responseObject];
        if (success) {
            success(model);
        }
    } failure:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
    return task;
}

// 获取用户信息

+ (NSURLSessionDataTask *)requestgetuserInfosuccess:(void(^)(MGUserInfoModel *model))success
                                            failure:(FailureResponseBlock)failure{
    NSString *api = @"/app/user/getUserInfo";
  
    NSURLSessionDataTask *task = [MGRequestService dataTaskWithMethodType:MGHTTPMethodTypeGET api:api parameters:nil success:^(id responseObject) {
        MGUserInfoModel *model = [MGUserInfoModel MJmodelWithResponseObject:responseObject];
        if (success) {
            success(model);
        }
    } failure:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
    return task;
}

+ (NSURLSessionDataTask *)requestupdateUserInfoWithUserInfo:(MGUserInfoModel *)model   success:(void(^)(MGBaseRspModel *model))success
                                                    failure:(FailureResponseBlock)failure{
    NSString *api = @"/app/user/updateUserInfo";
    NSDictionary *parameters =[NSMutableDictionary dictionaryWithObjectsAndKeys:model.nickName,@"nickName",@(model.age),@"age",@(model.workStauts),@"workStauts",@(model.sociaSecurity),@"sociaSecurity",@(model.accumulationFund),@"accumulationFund",@(model.haveHouse),@"haveHouse",@(model.haveCar),@"haveCar", nil];
    
    NSURLSessionDataTask *task = [MGRequestService dataTaskWithMethodType:MGHTTPMethodTypePOST api:api parameters:parameters success:^(id responseObject) {
        MGBaseRspModel *model = [MGBaseRspModel MJmodelWithResponseObject:responseObject];
        if (success) {
            success(model);
        }
    } failure:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
    return task;
}

// 获取产品列表

+ (NSURLSessionDataTask *)requestgetProductListWithtype:(int)productType andorderAmount:(int)orderAmount andorderTerm:(int)orderTerm andpageIndex:(int)pageIndex andpageSize:(int)pageSize  success:(void(^)(MGBaseRspModel *model))success
                                                failure:(FailureResponseBlock)failure{
    NSString *api = @"/app/product/getProductList";
    NSDictionary *parameters =[NSMutableDictionary dictionaryWithObjectsAndKeys:@(productType),@"productType",@(orderAmount),@"orderAmount",@(orderTerm),@"orderTerm",@(pageIndex),@"pageIndex",@(pageSize),@"pageSize", nil];
    NSLog(@"parameters %@",parameters);
    NSURLSessionDataTask *task = [MGRequestService dataTaskWithMethodType:MGHTTPMethodTypePOST api:api parameters:parameters success:^(id responseObject) {
        MGBaseRspModel *model = [MGBaseRspModel MJmodelWithResponseObject:responseObject];
        if (success) {
            success(model);
        }
    } failure:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
    return task;
}

+ (NSURLSessionDataTask *)requestgetProductInfo:(int)productId success:(void(^)(MGBaseRspModel *model))success
                                        failure:(FailureResponseBlock)failure{
    NSString *api = @"/app/product/getProductInfo";
    NSDictionary *parameters =[NSMutableDictionary dictionaryWithObjectsAndKeys:@(productId),@"id", nil];
    
    NSURLSessionDataTask *task = [MGRequestService dataTaskWithMethodType:MGHTTPMethodTypePOST api:api parameters:parameters success:^(id responseObject) {
        MGBaseRspModel *model = [MGBaseRspModel MJmodelWithResponseObject:responseObject];
        if (success) {
            success(model);
        }
    } failure:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
    return task;
}

+ (NSURLSessionDataTask *)requestaddApplyOrder:(int)productId success:(void(^)(MGBaseRspModel *model))success
                                       failure:(FailureResponseBlock)failure
{
    NSString *api = @"/app/product/addApplyOrder";
    NSDictionary *parameters =[NSMutableDictionary dictionaryWithObjectsAndKeys:@(productId),@"productId", nil];
    
    NSURLSessionDataTask *task = [MGRequestService dataTaskWithMethodType:MGHTTPMethodTypePOST api:api parameters:parameters success:^(id responseObject) {
        MGBaseRspModel *model = [MGBaseRspModel MJmodelWithResponseObject:responseObject];
        if (success) {
            success(model);
        }
    } failure:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
    return task;
}
@end
